# 定义集合
my_set = {"传智教育", "黑马程序员", "itheima", "传智教育", "黑马程序员", "itheima", "传智教育", "黑马程序员", "itheima"}
my_set_empty = set() # 定义空集合
print(f"my_set的内容是:{my_set}, 类型是: {type(my_set)}")
print(f"my_set_empty的内容是:{my_set_empty}, 类型是: {type(my_set_empty)}")
# 结论：集合类型内的元素不重复并且顺序也是乱序输出的

# 添加元素
my_set.add("Python")
print(my_set)

# 移除元素
my_set.remove("传智教育")
print(my_set)

# 从集合中随机取出元素
element = my_set.pop()
print(my_set)
print(element)

# 清空集合
my_set.clear()
print(my_set)

# 取出2个集合的差集
set1 = {1, 3, 5}
set2 = {1, 7, 9}
set3 = set1.difference(set2)
print(set1)
print(set2)
print(set3)

# 消除2个集合的差集
set1 = {1, 3, 5}
set2 = {1, 7, 9}
set1.difference_update(set2)
print(set1)
print(set2)

# 2个集合合并
set1 = {1, 3, 5}
set2 = {1, 7, 9}
set3 = set1.union(set2)
print(set1)
print(set2)
print(set3)

# 统计集合元素数量
set1 = {1, 3, 5}
numbers = len(set1)
print(numbers)

# 集合遍历
set1 = {1, 3, 5}
for element in set1:
    print(element)